home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
BSPSIZE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-13
|
5KB
|
177 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: bspsize.c
// Title: Base library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains code to determine the memory requirement of an
// active DOS mode program. This function does nothing on other operating
// systems.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <bs.h>
//----------------------------------------------------------------------------
// Data types
//----------------------------------------------------------------------------
#if OS_DOS && COMPILER_BORLAND
#pragma option -a-
typedef struct // Structure defining format of
{ // DOS MCB
CHAR chType; // Type 'M' or 'Z'
USHORT usOwner; // Owner segment
USHORT usParas; // Number of paragraphs
} _FAR_ *PMCB;
#endif
//----------------------------------------------------------------------------
// Description: Compute program size and other memory usage data.
// These values are only meaningful under dos. Under
// other OS's, dummy values are returned.
// Parameters: plProgram Pointer to variable to recieve total bytes
// used by current program
// plFree Pointer to variable to recieve total bytes
// free.
// Returns:
//----------------------------------------------------------------------------
VOID FN_E ProgramSize(PLONG plProgram, PLONG plFree)
{
#if OS_DOS && COMPILER_BORLAND
USHORT usMcbSeg;
LONG lFree = 0;
LONG lProgram = 0;
PMCB pmcb;
_asm { // Get segment of first MCB
mov ah, 52h // from DOS 'invars'
int 21h
sub bx, 2
mov ax, es:[bx]
mov [usMcbSeg], ax
}
do // Search MCB chain for first child
{
pmcb = (PMCB)(((ULONG)usMcbSeg) << 16);
if (pmcb->usOwner == _psp)
{
lProgram += pmcb->usParas;
}
else if (!pmcb->usOwner)
{
lFree += pmcb->usParas;
}
usMcbSeg += pmcb->usParas + 1; // Skip to next
}
while (pmcb->chType == 'M');
lProgram *= 16;
lFree *= 16;
if (plProgram)
plProgram[0] = lProgram;
if (plFree)
plFree[0] = lFree;
#else
if (plProgram)
plProgram[0] = 1L; // 1 byte (token value)
if (plFree)
plFree[0] = 1024L * 1024L * 32L; // 32 Mb
#endif
return ;
}
//----------------------------------------------------------------------------
// Description: Compute program size and other memory usage data.
// Write this information to a file!
// Parameters:
// Returns:
//----------------------------------------------------------------------------
VOID FN_E ProgramSizeShow(PCSZ pszLocation)
{
FILE *file;
LONG lFree;
LONG lProgram;
if (!LogEnabled())
return ;
ProgramSize(&lProgram, &lFree);
if ((file = fopen("size.log", "a+t")) == NULL)
return ;
fprintf(file,
"Program size %s.\n"
" Program: %8ld bytes (%6ld K)\n"
" Unused: %8ld bytes (%6ld K)\n"
" -------------- -----------\n"
" Available: %8ld bytes (%6ld K)\n\n",
pszLocation,
lProgram, (long)K(lProgram),
lFree, (long)K(lFree),
lFree+lProgram, (long)K(lFree + lProgram));
fclose(file);
return ;
}
//----------------------------------------------------------------------------
// Description: Run standard test suite
// Parameters: sTest Test to run.
// 0 Run all default tests (except).
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_TEST
BOOL FN ProgSizeTest(SHORT sTest)
{
LONG lFree;
LONG lProgram;
NOTUSED(sTest);
ProgramSize(&lProgram, &lFree);
Output("%ld bytes used.\n%ld bytes free. %ld total.\n",
lProgram, lFree, lProgram+lFree);
ProgramSizeShow("in test.");
return TRUE;
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------